<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title>提交订单-{$site_name}</title>
	<meta name="keywords" content="{$site_seo_keywords}" />
	<meta name="description" content="{$site_seo_description}">
	<tc_include file="Public:head" />
</head>
<body>
	<!---头部开始--->
	 <tc_include file="Public:header2" />
	<!---头部结束--->
	<div class="k-row buy-cart">
		<form name="cart_price_form" id="cart_price_form" method="post">
		<div class="b-panel">
			<div class="hd">
				<span>收货信息</span>
			</div>
			<div class="bd">
				<div class="buy-address">
					
					<div id="default_address"><!--ajax 返回收货地址--></div>
				</div>
				
			</div>
		</div>		
		<div class="g-list">
			<table width="100%" border="0" cellspacing="0" cellpadding="1">
				<tr class="ca-tt">
					<th align="center" valign="middle" colspan="2" width=300>商品</th>
					<th align="center" valign="middle" width=250>单价</th>
					<th align="center" valign="middle" width=150>数量</th>
					<th align="center" valign="middle" width=250>小计</th>					
				</tr>
				<if condition="$top_buy eq 'buy'">
					<tr class="ca-ss">
						<input type="hidden" name="to_buy" value="buy" />
						<td class="w-pic" width="80px" align="center" valign="middle">
							<a class="" href="{:leuu('article/index',array('g_id'=>$buyGoods['goods_id']))}">
								<img class="wi63 hi63" src="{$buyGoods.goods_id|goods_thumb_images=80,80}">
							</a>
						</td>
						<td class="wi516" align="left" valign="middle">
							<p>
								<a href="{:leuu('article/index',array('g_id'=>$buyGoods['goods_id']))}" style="vertical-align:middle">{$buyGoods.goods_name}</a>                          
							</p>
							<p>{$buyGoods.item_name}</p>
						</td>											   
						<td align="center" valign="middle"><span>￥{$buyGoods.shop_price}</span></td>								
						<td align="center" valign="middle">{$buyGoods.buy_num}</td>
						<td align="center" valign="middle">￥{$total_price.total_fee}</td>        
				    </tr>
				<else />
				<foreach name="cartList" item="v"  key="k">
                <if condition="$v[selected] eq '1'">
					<tr class="ca-ss">       
						<td class="w-pic" width="80px" align="center" valign="middle">
							<a class="" href="{:leuu('article/index',array('id'=>$v['goods_cat_id'],'g_id'=>$v['goods_id']))}">
								<img class="wi63 hi63" src="{$v.goods_id|goods_thumb_images=80,80}">
							</a>
						</td>
						<td class="wi516" align="left" valign="middle">
							<p>
								<a href="{:leuu('article/index',array('id'=>$v['goods_cat_id'],'g_id'=>$v['goods_id']))}" style="vertical-align:middle">{$v.goods_name}</a>                          
							</p>
							<p>{$v.spec_item_name}</p>
						</td>											   
						<td align="center" valign="middle"><span>￥{$v.goods_price}</span></td>								
						<td align="center" valign="middle">{$v.goods_num}</td>
						<td align="center" valign="middle">￥{$v.goods_fee}</td>        
				    </tr>
				</if>
                </foreach> 
				</if>
			</table>
        </div>
		
		<div class="b-panel">
			<div class="hd">
				<span>支付方式</span>
			</div>
			<div class="bd">
				<div class="pay-select j-spec">
					<div class="pay-st active">
					<input type="radio" name="pay_status" value="online" style="display:none;" checked="checked" />
					在线支付
					<span class="sku-icon" ></span>
					</div>				
					<div class="pay-st">
					<input type="radio" name="pay_status" value="cash" style="display:none;" />
					货到付款
					<span class="sku-icon" ></span>
					</div>
				</div>				
			</div>
		</div>
			<div class="pay-box">
				<div class="p-sum fr">
					<p><span class="t1">商品合计：</span><span class="t2"><em class="tr">￥</em>{$total_price.total_fee}</span></p>
					<p><span class="t1">运费：</span><span class="t2"><em class="tr">￥</em>0</span></p>
					<div class="clear"></div>
					<div class="am-pay">
						<p><span class="t1">应付金额：</span><span class="t2"><em class="tr">￥</em><em class="t-n" id="payables">0</em></span></p>
					</div>
					<div class="order-submit fr">
						<div class="btn btn-on" onclick="submit_order()">提交订单</div>						
					</div>
				</div>				
			</div>
		</form>
	</div>
	<!---底部开始--->
	<tc_include file="Public:footer"/>
	<!---底部结束--->
	<tc_include file="Public:scripts" />
	<script type="text/javascript">
		$(document).ready(function(){
			default_address(); // 获取用户收货地址列表
			ajax_order_price(); //计算价格
		});
	</script>
	<script type="text/javascript">
		/*
		* ajax 获取当前用户默认收货地址
		*/
		function default_address(){
			$.ajax({
				url:"{:U('User/address/getAddress')}",//+tab,
				success: function(data){
					$("#default_address").html('');
					$("#default_address").append(data);					
				}
			});
		}
	</script>
	
	<script type="text/javascript">
		/*
		* ajax 获取当前用户的收货地址列表
		*/
		function ajax_address(){
			$.ajax({
				url:"{:U('User/address/ajaxAddress')}",//+tab,				
				success: function(data){
					//$("#ajax_address").html('');
					//$("#ajax_address").append(data);					
					layer.open({
					  type: 1,
					  title: '收货信息',
					  shadeClose: true,
					  shade: 0.8,
					  area: ['550px', '640px'], //宽高
					  content: data
					});					
				}
			});
		}
	</script>
	<script type="text/javascript">
		function del_address(id)
		{
			$.ajax({
				url:"/index.php?g=User&m=address&a=del_address&id="+id,
				success: function(data){
					ajax_address(); // 刷新收货地址
					default_address(); // 刷新收货地址
				}
			});	  	  
		}
	</script>
	<script type="text/javascript">
		//计算价格
		function ajax_order_price(){
			
			$.ajax({
				type : "POST",
				url:"{:U('Goods/Cart/cart_buy_order')}",//+tab,
				data : $('#cart_price_form').serialize()+"&act=order_price",// 你的formid
				dataType: "json",
				success: function(data){
					
					if(data.status != 1)
					{
						
						layer.msg(data.msg, {					    
							time: 2000 //2秒关闭
						}, function(){ // 关闭后执行的函数
							location.href ="__ROOT__/";
						});								
						// 登录超时
						if(data.status == -100) 
							location.href ="{:U('user/login/index')}";
										
						return false;
					}
								
					$("#payables").text(data.result.payables);// 应付				
								
				}
			});
		}
	</script>
	<script type="text/javascript">
		//设置默认收货地址
		function ajaxDefaultAddress()
		{
			var id = $(".address-list .active").data("id");			
			$.ajax({
				url:"/index.php?g=User&m=address&a=ajaxDefaultAddress&id="+id,
				success: function(data){
					layer.closeAll('page');
					default_address(); // 刷新收货地址
				}
			});	  	  
		}
	</script>
	<script type="text/javascript">
		//弹出添加编辑收货地址
		function addresssBox(_type){			
			var _html = '/index.php?g=User&m=address&a=index&type='+ _type;							
			layer.open({
				type: 2,
				title: '收货信息',
				shadeClose: true,
				shade: 0.8,
				area: ['800px', '520px'],
				content: _html,
			});							 
		}
	</script>
	<script type="text/javascript">
		// 提交订单
		ajax_return_status = 1;
		function submit_order()
		{
			if(ajax_return_status == 0)
				return false;
				
			ajax_return_status = 0;	
				
			$.ajax({
				type : "POST",
				url:"{:U('Goods/Cart/cart_buy_order')}",//+tab,
				data : $('#cart_price_form').serialize()+"&act=submit_order",// 你的formid
				dataType: "json",
				success: function(data){
														
					if(data.status != '1')
					{
						// alert(data.msg); //执行有误						
						layer.msg(data.msg,{time:2000});
						// 登录超时
						if(data.status == -100) 
							location.href ="{:U('Home/User/login')}";
						
						ajax_return_status = 1; // 上一次ajax 已经返回, 可以进行下一次 ajax请求
						
						return false;
					}
					
					layer.msg('订单提交成功，正在跳转!', {					    
					  time: 2000 //2秒关闭（如果不配置，默认是3秒）
					}, function(){ // 关闭后执行的函数
							location.href = "/index.php?g=Goods&m=Cart&a=topay&order_id="+data.result; // 跳转到结算页
					});			
				}
			});	
		}
	</script>
	<script type="text/javascript">
	 $(".pay-select").on("click", ".pay-st", function () {
                var input = $(this).find("input");
                
                    $(".pay-st").find("input").each(function () {
                        $(this).removeAttr("checked");
                    });
                    $(input).attr("checked", true);
					
                
				var _check = $('input:radio[name="pay_status"]:checked').val();
				if(_check){
					$(input).parent().addClass('active');
					$(input).parent().siblings().removeClass('active');
				}
            });
	</script>
</body>
</html>